package com.leps.nq.op.controller;

import com.leps.nq.common.aspect.Log;
import com.leps.nq.common.enums.BusinessType;
import com.leps.nq.common.vo.PageVo;
import com.leps.nq.common.vo.R;
import com.leps.nq.common.vo.RBuilder;
import com.leps.nq.op.entity.OpDeviceMaintenance;
import com.leps.nq.op.service.IOpDeviceMaintenanceService;
import com.leps.nq.op.vo.DeviceMaintenanceQueryModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 设备运维(保养)记录表 前端控制器
 * </p>
 *
 * @author hex
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/op/op-device-maintenance")
@Api(tags = "设备运维日志管理")
public class OpDeviceMaintenanceController {
    @Autowired
    IOpDeviceMaintenanceService deviceMaintenanceService;
    @GetMapping
    @ApiOperation("设备运维日志列表")
    public R<PageVo<OpDeviceMaintenance>> list(DeviceMaintenanceQueryModel queryModel) {
        PageVo<OpDeviceMaintenance> pageVo = this.deviceMaintenanceService.pageByQueryModel(queryModel);
        return RBuilder.ok(pageVo);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询设备运维日志")
    public R<OpDeviceMaintenance> getById(@PathVariable Long id) {
        return RBuilder.ok(this.deviceMaintenanceService.getById(id));
    }

    @PostMapping
    @ApiOperation("新增运维日志")
    @Log(title = "运维日志", businessType = BusinessType.INSERT)
    public R<?> save(@RequestBody OpDeviceMaintenance deviceMaintenance) {
        return RBuilder.ofBoolean(this.deviceMaintenanceService.save(deviceMaintenance));
    }

    @DeleteMapping
    @ApiOperation("删除设备运维日志")
    @Log(title = "运维日志", businessType = BusinessType.DELETE)
    public R<?> remove(@RequestBody List<Long> deviceMaintenanceIds) {
        boolean b = this.deviceMaintenanceService.removeBatchByIds(deviceMaintenanceIds);
        return RBuilder.ofBoolean(b);
    }

    @PutMapping
    @ApiOperation("修改设备运维日志")
    @Log(title = "运维日志", businessType = BusinessType.UPDATE)
    public R<?> update(@RequestBody OpDeviceMaintenance deviceMaintenance) {
        return RBuilder.ofBoolean(this.deviceMaintenanceService.updateById(deviceMaintenance));
    }
}
